<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html>
<html style="height:100%">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>左侧菜单树</title>
<%@ include file="/WEB-INF/jsp/common/inc.jsp" %>
<!--  树结构  -->
	<script type="text/javascript">

		var	parentId;
		var ztree;
		var setting = {
			view: {
				fontCss : {border:"0",background:"none","text-decoration":"none"},
				showIcon: false,
				showLine: true,
				selectedMulti: false,
				dblClickExpand: false
			},
			data: {
				simpleData: {
					enable: true,
					idKey: "menuId",
					pIdKey: "parentId"
				}
			},
			callback: {
				onNodeCreated: this.onNodeCreated,
				onClick:onClick
			}
		};

		var zNodes = eval('(${menuList})');

		var myWork = "";
		$(document).ready(function(){
			myWork = "1";
			ztree = $.fn.zTree.init($("#treeDemo"), setting, zNodes);
			if("zuzhizichan" == "${needExpandNodeId}"){
				var div = document.getElementById("templatelist");
				div.src ="${_baseUrl}/organizeassetsKTController/showOrganizeassetsIndex?parentMenuId=${menuInfo.menuId}"+"&random="+Math.random();
			}else{
				ztree.expandNode(ztree.getNodeByParam("menuId","${needExpandNodeId}",null));//展开指定节点
				ztree.setting.callback.onClick(null, ztree.setting.treeId, ztree.getNodeByParam("menuId","${needExpandNodeId}",null));//触发函数
			}
			loadTree("${needExpandNodeId}");
			$("#menuName").click(function(){
				if(this.innerText.indexOf("组织资产") != -1){
					ztree.expandNode(ztree.getNodeByParam("menuId","${needExpandNodeId}",null));//展开指定节点
					var div = document.getElementById("templatelist");
					div.src ="${_baseUrl}/organizeassetsKTController/showOrganizeassetsIndex?parentMenuId=${menuInfo.menuId}"+"&random="+Math.random();
				}
			});
		});
		function loadTree(nodeId){
			myWork = "1";
			ztree = $.fn.zTree.init($("#treeDemo"), setting, zNodes);
			ztree.selectNode(ztree.getNodeByParam("menuId",nodeId,null));//选中指定节点
			ztree.setting.callback.onClick(null, ztree.setting.treeId, ztree.getNodeByParam("menuId",nodeId,null));//触发函数
		}


		function onClick(e,treeId, treeNode) {
			var projectId = "${projectId}";
			var source = "${source}";
			if(myWork != '1'){
				projectId = "";
			}
			myWork ="";
			parentId=treeNode.menuId;
			var zTree = $.fn.zTree.getZTreeObj("treeDemo");
			zTree.expandNode(treeNode);
			var div = document.getElementById("templatelist");
			var nodeUrl = "${_baseUrl}"+treeNode.menuUrl+"?menuId="+treeNode.menuId+"&id=${id}&projectstatus=${projectstatus}&nodeId=${id}&projectId="+projectId;
			if (treeNode.name == "文档通用章节"){
				nodeUrl = "${_baseUrl}"+treeNode.menuUrl+"?parentMenuId=" + parentId;
			}
			//是否是从待办跳转
			if(source == "daiban" ){
				nodeUrl = "${_baseUrl}"+treeNode.menuUrl+"?menuId="+treeNode.menuId+"&id=${id}&projectstatus=${projectstatus}&nodeId=${id}&projectId="+projectId+"&source="+source;
			}
	
			// 修改 bug [#15391] 在文档开发--项目管理，构建项目成功后跳转至 文档开发--文档编制--项目基本信息界面
			if(source == "taskAssign" && projectId != "" ){
		       	nodeUrl="${_baseUrl}/documentList/showProjectAndDocument?projectId="+projectId+"&id=${id}";
		    }
			if ((treeNode.name == "典型用例库" && treeNode.menuUrl =='/typicalCase/showTypicalCaseIndex') || (treeNode.name == "测试资产" && treeNode.menuUrl =='/typicalCase/showTypicalCaseIndex')){
				if("${customCode}" === "tianjin712suo"){
					// 712 定制
					var newTreeNode = treeNode;
					if(typeof(treeNode.children) != "undefined"){
						var childrenNodes = treeNode.children;
						newTreeNode = childrenNodes[0];
					}
					zTree.cancelSelectedNode();
					ztree.selectNode(ztree.getNodeByParam("menuId",newTreeNode.menuId,null));//选中指定节点
					nodeUrl = "${_baseUrl}"+newTreeNode.menuUrl+"?menuId="+newTreeNode.menuId+"&id=${id}&projectstatus=${projectstatus}&nodeId=${id}&projectId="+projectId+"&source=1";
				}else{
					nodeUrl = "${_baseUrl}"+treeNode.menuUrl+"?menuId="+treeNode.menuId+"&id=${id}&projectstatus=${projectstatus}&nodeId=${id}&projectId="+projectId+"&source=1";
				}
			}

			div.src = nodeUrl+"&random="+Math.random();
		}

		function skip(url,menuId){
			var div = document.getElementById("templatelist");
			if(url.indexOf("showTestProcessDemandMenu") != -1){
				var projectId = url.substring(url.indexOf("=")+1,url.indexOf("&"));
				parent.skipModule1("测试管理","${_baseUrl}/jurisdiction/menuList",'',"d42f113426d7436ba1683856cc1697a1",projectId,"","");
			}else{
				if(url.indexOf("?") > 0){
					div.src ="${_baseUrl}"+url+"&menuId="+menuId+"&random="+Math.random();
				}else{
					div.src ="${_baseUrl}"+url+"?menuId="+menuId+"&random="+Math.random();
				}
			}
		}

		function skipModule1(moduleName,url,clickNodeId,menuId,projectId,id,projectstatus){

			parent.skipModule1(moduleName,url,clickNodeId,menuId,projectId,id,projectstatus);
		}

		function skipModule(menuName,url,menuId){
			ztree = $.fn.zTree.init($("#treeDemo"), setting, zNodes);
			ztree.selectNode(ztree.getNodeByParam("menuId",menuId,null));//选中指定节点
			if(url != null && url != ""){
				var div = document.getElementById("templatelist");
				div.src = url;
			}
		}


		function skipParentModule(menuName){
			parent.skipModule(menuName,"");
		}

		function refreshTree(){
			var menuId="${menuInfo.menuId}";
			$.ajax({
				url : "${_baseUrl}/jurisdiction/menuTreeList?menuId="+menuId,
				type : "post",
				dataType : "json",
				async : false,//** ！重要 同步请求。效果:ajax未进行则其他代码不运行
				success : function(json) {
					if(json.code=="1"){
						zNodes= eval(json.data);
						ztree = $.fn.zTree.init($("#treeDemo"), setting, zNodes);
						ztree.selectNode(ztree.getNodeByParam("menuId",parentId,null));//选中指定节点
						ztree.expandNode(ztree.getNodeByParam("menuId",parentId,null));//展开指定节点
						$("#menuName").click(function(){
							if(this.innerText.indexOf("组织资产") != -1){
								ztree = $.fn.zTree.init($("#treeDemo"), setting, zNodes);
								ztree.expandNode(ztree.getNodeByParam("menuId","${needExpandNodeId}",null));//展开指定节点
								var div = document.getElementById("templatelist");
								div.src ="${_baseUrl}/organizeassets/showOrganizeassetsIndex?random="+Math.random();
							}
						});
					}
				},
				error:function(data){
					layer.msg("系统错误,请联系管理员");
				}
			});
		}
		function gotoProjectBaseInfo(projectId,projectStatus){
			//parent.location.href="${_baseUrl}/projectKt/showProjectBaseinfo?projectId="+projectId;
			var path = "${_baseUrl}/projectKt/showProjectBaseinfo?projectId="+projectId+"&sonPage=yes"+"&random="+Math.random();
			if(projectStatus == '1'){
				layerIndex =layer.open({
					type: 2,
					title:'设置项目详细信息',
					area: ['900px', '400px'],
					fixed: false, //不固定
					maxmin: true,
					shim: true,
					content: path,
					success: function(){

					},
					moveEnd: function(layero){

					},
					cancel: function(){
						layer.closeAll();
					}
				});
				layer.full(layerIndex);
			}else if(projectStatus == undefined){
				path = "${_baseUrl}/projectKt/showProjectBaseinfo?projectId="+projectId+"&sonPage=yes&build=yes"+"&random="+Math.random();
				layerIndex =layer.open({
					type: 2,
					title:'设置项目详细信息',
					area: ['900px', '400px'],
					fixed: false, //不固定
					maxmin: true,
					shim: true,
					content: path,
					success: function(){

					},
					moveEnd: function(layero){

					},
					cancel: function(){
						layer.closeAll();
					}
				});
				layer.full(layerIndex);
			}else{
				layerIndex = layer.open({
					type: 2,
					title:'修改项目详细信息',
					area: ['900px', '400px'],
					fixed: false, //不固定
					maxmin: true,
					shim: true,
					content: path,
					success: function(){

					},
					moveEnd: function(layero){

					},
					cancel: function(){
						layer.closeAll();
					}
				});
				layer.full(layerIndex);
			}
		}

		function gotoProjectBaseInfoView(projectId){
			var path = "${_baseUrl}/projectView/showProjectBaseinfoView?projectId="+projectId+"&random="+Math.random();
			layerIndex = layer.open({
				type: 2,
				title:'项目详细信息',
				area: ['900px', '400px'],
				fixed: false, //不固定
				maxmin: true,
				shim: true,
				content: path,
				success: function(){

				},
				moveEnd: function(layero){

				},
				cancel: function(){
					layer.closeAll();
				}
			});
			layer.full(layerIndex);
		}

		/* 关闭弹出框 */
		function closeWin(){
			layer.closeAll();
		}

		function defineTemplateSort(){
			layer.open({
				type: 2,
				title:'类别管理',
				area: ['500px', '370px'],
				shade: 0.3, //遮罩透明度
				fixed: false, //不固定
				maxmin: true,
				shim: true,
				content: '${_baseUrl}/OMenuDescribe/showOrganizeassetsMenuTree?menuId=${parentMenuId}'+'&random='+Math.random(),
				cancel: function(index, layero){
					layer.close(index)
					window.location.reload(true);
				}
			});
		}
		/* 重新出发一次最后点击的节点 */
		function onclickLastMenu(){
			var zTree = $.fn.zTree.getZTreeObj("treeDemo");
			zTree.setting.callback.onClick(null, zTree.setting.treeId, zTree.getNodeByParam("nodeId",lastOnClickNodeId,null));//触发函数
		}

		function showAllAssets() {
			var div = document.getElementById("templatelist");
			var url = "${_baseUrl}/organizeassetsKTController/showOrganizeassetsIndex?parentMenuId=${menuInfo.menuId}";
			div.src = url+"&random="+Math.random();
		}

	</script>
	<script type="text/javascript" src="${_resources}js/jquery.ztree.core.js"></script>
	<link rel="stylesheet" href="${_resources}css/zTreeStyle.css" type="text/css">
	<link href='${_resources}css/style.css' type='text/css' rel='stylesheet' />
<style type="text/css">
.main_left .ztree li a{color:#666;height:25px;line-height:25px;padding: 0px 3px 0 0;}
.ztree li a.curSelectedNode{padding: 0px 3px 0 0;}
</style>

</head>
<body style="height:100%">

<div class="main">
    <div id="main-left" class="zTreeDemoBackground main_left" style="padding-bottom: 10px;width:150px">
       	<c:if test="${menuInfo.menuId == '11111' or menuInfo.menuId == '22222'}">
        	<%--<div style="margin-top:9px">
		       <a class="aaaaa" href="${_baseUrl}/organizeassetsKTController/showOrganizeassetsIndex?parentMenuId=${menuInfo.menuId}" target='aaaaaaa' style="font-size: 14px;color:#666;margin-left:15px">全部资产</a>
		       <c:if test="${menuInfo.menuId == '22222'}">
		       		<a onclick="defineTemplateSort();" id="newTestRequirements" href="javascript:;" style="float:right;background-color: #fff;color: #3979FF;font-size: 14px;padding:0px 8px 4px;">类别管理</a>
		       </c:if>	
		    </div>--%>
			<c:if test="${customCode ne 'tianjin712suo'}">
				<div style="margin-top:9px">
					<a class="aaaaa" href="${_baseUrl}/organizeassetsKTController/showOrganizeassetsIndex?parentMenuId=${menuInfo.menuId}" target='aaaaaaa' style="font-size: 14px;color:#666;margin-left:15px">全部资产</a>
					<c:if test="${menuInfo.menuId == '22222'}">
						<a onclick="defineTemplateSort();" id="newTestRequirements" href="javascript:;" style="float:right;background-color: #fff;color: #3979FF;font-size: 14px;padding:0px 8px 4px;">类别管理</a>
					</c:if>
				</div>
			</c:if>

			<c:if test="${customCode eq 'tianjin712suo'}">
				<div style="margin-top:19px" id="showAllAssetsId">
					<a class="aaaaa" onclick="showAllAssets();" style="font-size: 14px;color:#666;margin-left:15px">全部资产</a>
				</div>
		    </c:if>	
		    <ul id="treeDemo" class="ztree"></ul>
        </c:if>
        <c:if test="${menuInfo.menuId != '11111' and menuInfo.menuId != '22222'}">
        	<ul id="treeDemo" class="ztree"></ul>
        </c:if>
    </div> 
     <div id="btn" class="btn">
		<div id="cont_a" class="close_a" onclick="slipHidden();"></div>
		<div id="cont_b" class="open" onclick="slipShow();" style="display:none;"></div>
	</div>
    <!-- 图标按钮结束 -->
    <div id="main-right" class="main_right" >
        <iframe id="templatelist" name="win" width='100%' height='100%' src="" frameborder="0" scrolling="auto">
        </iframe>
    </div>
</div>
</body>
<script type="text/javascript">
	var  resizeTimer = null;
	window.onload = function(){
		initWidth();
		initHeight();
	}
	window.onresize = function(){
	    if(resizeTimer) clearTimeout(resizeTimer);
	    resizeTimer = setTimeout("initHeight();initWidth();",100);
	 }
	function initHeight(){
		var topH = 0; 
		if(navigator.userAgent.indexOf("MSIE")>0 || navigator.userAgent.indexOf("like Gecko")>0) {//IE浏览器
			initheight = document.documentElement.clientHeight-topH;
		}
		if(navigator.userAgent.indexOf("Firefox")>0){//Firefox浏览器
			initheight = document.documentElement.clientHeight-topH;
		}
		if(navigator.userAgent.indexOf("Opera")>0){//Opera浏览器
			initheight = document.body.clientHeight-topH;
		}
		if(navigator.userAgent.indexOf("Chrome")>0){//Chrome谷歌浏览器
			initheight = document.documentElement.clientHeight-topH;
		}
		if(navigator.userAgent.indexOf("Safari")>0){//Safari浏览器
			initheight = document.documentElement.clientHeight-topH;
		}
		$("#btn").css( "height",initheight-5);
	    $("#btn").css( {"position":"relative"});
	    $("#main-left").css( "height",initheight+0);
	    $("#main-left").css( "overflow","hidden");
	    $("#main-right").css( "height",initheight);
	    $("#treeDemo").css( "height",initheight+0);
	}
	function initWidth(){
		var oMaBox = document.getElementById("main-left");
		var topW = oMaBox.getBoundingClientRect().width; 
		
		if(navigator.userAgent.indexOf("MSIE")>0 || navigator.userAgent.indexOf("like Gecko")>0) {//IE浏览器
			topW = oMaBox.clientWidth;
			initwidth = document.documentElement.clientWidth-topW;
		}
		if(navigator.userAgent.indexOf("Firefox")>0){//Firefox浏览器
			initwidth = document.documentElement.clientWidth-topW;
		}
		if(navigator.userAgent.indexOf("Opera")>0){//Opera浏览器
			initwidth = document.body.clientWidth-topW;
		}
		if(navigator.userAgent.indexOf("Chrome")>0){//Chrome谷歌浏览器
			initwidth = document.documentElement.clientWidth-topW;
		}
		if(navigator.userAgent.indexOf("Safari")>0){//Safari浏览器
			initwidth = document.documentElement.clientWidth-topW;
		}
		$("#btn").css( {"position":"relative","left":topW-20});
		$("#main-right").css( {"width":initwidth,"position":"absolute","left":topW});
	}
	function slipHidden(){
		var oTop = document.getElementById("cont_a");
		var oDown = document.getElementById("cont_b");
		var oBox = document.getElementById("main-left");
		var oBtn = document.getElementById("btn");
		oTop.style.display = "none";
		oDown.style.display = "block";
		oBox.style.display = "none";
		initWidth();
		$("#btn").css("left","0px");
		var childWindow = $("#templatelist")[0].contentWindow;
		if(typeof(eval(childWindow.contIframe_a)) != 'undefined'){ 
			if(typeof(eval(childWindow.contIframe_a.s1))=='function'){
				window.win.s1();
				childWindow.contIframe_a.window.s1();
				//alert(11);
			}else if(typeof(eval(childWindow.s1))=='function'){
				childWindow.window.s1();
				//alert(22);//文档开发
			}
			
		} 
		
	}
	function slipShow(){
		var oTop = document.getElementById("cont_a");
		var oDown = document.getElementById("cont_b");
		var oBox = document.getElementById("main-left");
		var oBtn = document.getElementById("btn");
		oTop.style.display = "block";
		oDown.style.display = "none";
		oBox.style.display = "block";
		initWidth();
		var childWindow = $("#templatelist")[0].contentWindow;
		if(typeof(eval(childWindow.contIframe_a)) != 'undefined' ){ 
			if(typeof(eval(childWindow.contIframe_a.s2))=='function'){
				window.win.s2();
				childWindow.contIframe_a.window.s2();
			}else if(typeof(eval(childWindow.s2))=='function'){
				childWindow.window.s2();
			}
		} 
		
		
	}
</script>
</html>